package com.kitty.game.achieve.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.achieve.body.AchieveSet;
import com.kitty.game.achieve.body.RespAchieveViewDTO;
import com.kitty.game.achieve.message.*;
import com.kitty.game.achieve.service.AchieveConfigService;
import com.kitty.game.achieve.service.AchieveService;
import com.kitty.game.activity.message.ReqLingQu;
import com.kitty.game.enter.RespGeneralNotify;
import com.kitty.game.fixed.message.FixedTeamStartConfirm;
import com.kitty.game.npc.service.NewNpcService;
import com.kitty.game.role.model.Role;
import com.kitty.game.utils.NotifyModules;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class AchieveConfigController {
    @Autowired
    AchieveConfigService achieveConfigService;
    @Autowired
    AchieveService achieveService;

    public static void main(String[] args) throws IOException {

        for (Map.Entry<String, AchieveSet> sopu : DataCache.ACHIEVE_DATA.entrySet()) {
            //  System.out.println(sopu.getKey());
            // System.out.println(JSON.toJSON(sopu.getValue()));
        }
        File file = new File("D:\\demo1.txt");
        StringBuffer sb = new StringBuffer();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(file));
            String st;
            while ((st = br.readLine()) != null){
                sb.append(st);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        JSONObject ojb = JSONObject.parseObject(sb.toString());
        JSONObject smobj  =  JSONObject.parseObject(ojb.get("中洲轶事-光辉岁月").toString());
        int i = 1;
        for (Map.Entry<String, Object> stringObjectEntry : smobj.entrySet()) {
            String key = "";
            JSONObject c = JSONObject.parseObject(stringObjectEntry.getValue().toString());
            if(i<=9){
                key = "00"+i;
            }else if(i<=99){
                key = "0"+i;
            }else{
                key = i+"";
            }
            String a = "(\"%s\",\"%s\",%s,\"%s\",\"%s\");";
            a = String.format(a,"602",key,c.get("order").toString(),c.get("achieve_desc").toString(),stringObjectEntry.getKey());
            System.out.println("new AchieveSet"+a);
            i+=1;
        }
    }
    public String getType(String name){
        String a = "";

        return a;
    }
    @RequestMapping
    public void openAchieve(IoSession session, ReqAchieveView reqAchieveView){
        Role role = SessionUtils.getRoleBySession(session);
        // achieveService.sendAchieveConfig(role,reqAchieveView.getCategory()+"",false);
        //发送对应成就状态
        achieveService.queryAchieveByType(role,reqAchieveView);
    }



    @RequestMapping
    public void openAchieve(IoSession session, AchieveConfig AchieveConfig){
        Role role = SessionUtils.getRoleBySession(session);
        //发送成就配置
        achieveService.sendAchieveConfig(role,"1",true);

    }
    //打开成就总览页面
    @RequestMapping
    public void queryAchieveOverview(IoSession session, AchieveOverview achieveOverview){

        Role role = SessionUtils.getRoleBySession(session);

        //发送成就总览信息
        achieveService.sendAchieveAllView(role);
        //打开成就页面
        RespGeneralNotify respGeneralNotify2 = new RespGeneralNotify();
        respGeneralNotify2.setNotify((short) NotifyModules.NOTIFY_OPEN_DLG); //打开对话框
        respGeneralNotify2.setValue("AchievementListDlg");
        MessagePusher.pushMessage(session, respGeneralNotify2);

        //首杀
        achieveConfigService.queryFirstBossInfo(session);
        //boss图鉴
        RespBossImgList respBossImgList = achieveConfigService.queryBossImgList(session);
        MessagePusher.pushMessage(session, respBossImgList);


    }

    //打开boss图鉴页面
    @RequestMapping
    public void queryAchieveBossImg(IoSession session, ReqAchieveBossImg reqAchieveBossImg){
        achieveConfigService.queryAchieveBossImg(session);
    }

    //激活boss图鉴
    @RequestMapping
    public void jiHuoBossImg(IoSession session, ReqJiHuoBossImg reqJiHuoBossImg){
        achieveConfigService.jiHuoBossImg(session,reqJiHuoBossImg);
    }



    //领取按钮
    @RequestMapping
    public void queryLingQu(IoSession session, ReqLingQu reqLingQu){
        Role role = SessionUtils.getRoleBySession(session);
        SpringUtils.getBean(NewNpcService.class).requestNpcContent(role, 15019);
    }
}
